/*
 * Copyright (c) 2007 T.Cogghe, D.Leroux, S.Lévignac, S.Rives
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
#include "fenetreDark.hh"
#include "fenetreFinale.hh"




IHM::FenetreDark::FenetreDark(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade)
	: Gtk::Window(cobject), //m_refGlade(refGlade),
		b_imgNoire(0), br_algoAucun(0),	br_algoFreq(0),
		br_algoQte(0), br_algoImg(0), br_modeSub(0),
		br_modeGate(0)
{
	getW(refGlade,b_imgNoire,"b_fDark_ImageNoire");

	getW(refGlade,br_algoAucun,"fDark_algoAucun");
	getW(refGlade,br_algoFreq,"fDark_algoFreq");
	getW(refGlade,br_algoQte,"fDark_algoQte");
	getW(refGlade,br_algoImg,"fDark_algoImg");

	getW(refGlade,br_modeSub,"fDark_modeSub");
	getW(refGlade,br_modeGate,"fDark_modeGate");

	getW(refGlade,curs_qteAbs,"curs_fDark_qteAbs");

	dynamic_cast<Gtk::Button*>(refGlade->get_widget("b_fDark_annul"))->signal_clicked().connect(
		sigc::mem_fun(*this,&IHM::FenetreDark::annuler));

	dynamic_cast<Gtk::Button*>(refGlade->get_widget("b_fDark_valid"))->signal_clicked().connect(
		sigc::mem_fun(*this,&IHM::FenetreDark::valider));

	Gtk::Adjustment adj(80.,25.,99.9,0.01);
	curs_qteAbs->set_adjustment(adj);
	curs_qteAbs->set_digits(2);
}

IHM::FenetreDark::~FenetreDark() {}


void IHM::FenetreDark::valider() {
	/* TODO affecter les Dark::* */
	if(br_algoAucun->get_active()) {
		Image::Dark::algo=Image::Dark::Aucun;
	} else if(br_algoFreq->get_active()) {
		Image::Dark::algo=Image::Dark::PicFreq;
	} else if(br_algoQte->get_active()) {
		Image::Dark::algo=Image::Dark::QteAbs;
	} else if(br_algoImg->get_active()) {
		Image::Dark::algo=Image::Dark::ImgNoir;
		if(Image::Dark::imgNoir) {
			delete Image::Dark::imgNoir;
		}
		// TODO Image::Dark::imgNoir=new Image( <fetch filename from button> );
	}

	Image::Dark::absorption=.01*curs_qteAbs->get_value();

	if(br_modeSub->get_active()) {
		Image::Dark::mode=Image::Dark::Sub;
	} else if(br_modeGate->get_active()) {
		Image::Dark::mode=Image::Dark::Gate;
	}

	hide();
	IHM::env->demarreTraitement();
}


void IHM::FenetreDark::annuler() {
	hide();
}


